﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>ClientWinApp</title>

    <!-- WinJS references -->
    <link href="//Microsoft.WinJS.2.0/css/ui-dark.css" rel="stylesheet" />
    <script src="//Microsoft.WinJS.2.0/js/base.js"></script>
    <script src="//Microsoft.WinJS.2.0/js/ui.js"></script>

    <!-- ClientWinApp references -->
    <link href="/css/default.css" rel="stylesheet" />
    <script src="/js/default.js"></script>

    <!-- SignalR references -->
    <script src="/Scripts/jquery-1.6.4.js"></script>
    <script src="/Scripts/jquery.signalR-2.1.2.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
var connection = $.hubConnection('http://localhost:30526/signalr/hubs');
var hubProxy = connection.createHubProxy('helloWorld');

            hubProxy.on('connected', function (user, pesan) {
                var msg = new Windows.UI.Popups.MessageDialog("User baru bergabung.", "SignalR");
                msg.showAsync();
                console.log('User baru bergabung.');
            });

            hubProxy.on('show', function (user, pesan) {
                $('#AddText').append('<strong> ' + user + ' :</strong> ' + pesan + '<br />');
                console.log(user + ' : ' + pesan);
            });

            connection.start()
                .done(function ()
                {
                    $('#SubmitButton').click(function () {
                        hubProxy.invoke('Send', 'Win8 User', $('#PesanChat').val()).done(function () {
                            console.log('Send berhasil dieksekusi.');
                        }).fail(function (error) {
                            console.log('Send gagal dieksekusi. Error: ' + error);
                        });

                        $('#PesanChat').val('').focus();
                    });

                    console.log('Terkoneksi, connection ID=' + connection.id);
                })
                .fail(function () { console.log('Koneksi tidak dapat dilakukan'); });
        });
    </script>
</head>
<body>
    <input type="text" id="PesanChat" />
    <input type="button" id="SubmitButton" value="Send" />
    <div id="AddText"></div>
</body>
</html>
